Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP proxy support reworked #751

Conversation

andrewshadura
Copy link

@andrewshadura andrewshadura commented Apr 24, 2020

Hi,

I needed HTTP support in websockets, so I took an existing PR #422 and ported it to the latest version of the main code. Since start_tls has been available for a while now, the hack with upgrading HTTP to HTTPS is no longer needed.

My original implementation was a separate module overriding things and providing proxying support on top of the unmodified websockets library. I have tested that one quite a lot and then ported and integrated it back. I have not written any tests since I’m not quite sure how to approach this.

I have changed the implementation of ProxyURI to allow a trailing slash in the proxy URI. While this is non-standard, it seems to be widely supported and many users are unaware that the trailing slash is not supposed to be used in the proxy URIs.

What doesn’t work yet:

  • I have not yet touched redirects code; most likely redirects will try to connect bypassing the proxy
  • host and port keyword parameters change the host and port used to connect to the proxy, not the target
  • I was unable to get rid of one mypy error around proxy_uri parsing
  • I ran the code through black but didn’t agree with some changes it proposed
  • As mentioned above, some tests need to be written.

This fixes #364, supersedes and closes #422.

This is missing proper error handling and tests.
@andrewshadura andrewshadura force-pushed the http-proxy-support-reworked branch from b8ad1db to 4bc7408 Compare April 24, 2020 12:19
@andrewshadura
Copy link
Author

Oh well, last minute fixes without running tests — I should have not done that 🙂

@andrewshadura andrewshadura force-pushed the http-proxy-support-reworked branch from 4bc7408 to 16a1cd3 Compare April 24, 2020 12:24
@aaugustin
Copy link
Member

Preliminary note -- Python 3.6 is officially supported until 2021. It feels a bit early to drop support for this version. Perhaps we could make HTTP proxy support a Python 3.7+ only feature, while preserving compatibility with Python 3.6 for everything else.

@andrewshadura
Copy link
Author

andrewshadura commented Apr 28, 2020 via email

@aaugustin
Copy link
Member

Perhaps it's best if I spend more time reviewing before deciding on the next steps.

@andrewshadura andrewshadura force-pushed the http-proxy-support-reworked branch from 16a1cd3 to 65c0980 Compare May 4, 2020 12:06
@lambdalisue
Copy link

Great job @andrewshadura and @aaugustin! I'm looking froward to this. Is there anything I can help with?

@amatai
Copy link

amatai commented Sep 20, 2021

This is great. I am wanting to move from autobahn for its lack of proxy w/ asyncio support.
Can I help in this PR to get it part of release?

@andrewshadura
Copy link
Author

Unfortunately, there were some upstream changes which most likely conflict with my PR, so I guess it will require some significant rework once again.

@aaugustin
Copy link
Member

Support for Python 3.6 was dropped, which lifts the biggest blocker to this.

However, in the meantime, the library has undergone a major refactoring. I'm writing a "new" implementation on top of a Sans-I/O core, which will make it vastly easier to implement this feature. I'm increasingly reluctant to add features to what has become the "legacy" implementation because this increases the size of the target. Of course, all this doesn't really help you in the short term :-/

@berg223
Copy link

berg223 commented May 2, 2022

Thanks @andrewshadura I have changed code in my local repo of version 9.1 and it works for me! There is very little conflicts.

@aaugustin aaugustin force-pushed the main branch 2 times, most recently from 1726dba to 61e0e1c Compare August 24, 2022 06:15
@robsmith11
Copy link

@xiaocairush are you able to share the changes you made to get it working?

@andrewshadura
Copy link
Author

While we have deployed this code for the specific feature the customer has requested, the feature was well-tested and worked, they never enabled it in production, and will unlikely to do so short-term. Meanwhile we pinned websockets to version 8 to allow the external implementation to work, but I don’t intend to work on this PR any further unless the customer actually starts using it.

Given the amount of refactoring that happened in the project since this was submitted, I think a new PR with this functionality re-implemented once again in case of demand should be more appropriate 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for HTTP(S) proxies to connect()
6 participants